#include "numbertransform.h"
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include "verilated.h"
#include "Vtop.h"
#if VM_TRACE
#include <verilated_vcd_c.h>
#endif
using namespace std;

Vtop *top;
vluint64_t main_time = 0;
double sc_time_stamp() {
	return main_time;
}
double x = 0.0;
int y = 0;
double pi = 3.1415;
double A = 100;
double w = 100*pi;  // 2*pi*50.
double q = pi/4; // initial phase.

int main(int argc, char **argv, char **env) {
    if (0 && argc && argv && env) { }
    top = new Vtop;
    Verilated::commandArgs(argc, argv);
    Verilated::debug(0);

    #if VM_TRACE
        Verilated::traceEverOn(true);
	VL_PRINTF("Enabling waves...\n");
	VerilatedVcdC* tfp = new VerilatedVcdC;
        top->trace (tfp, 99);
	tfp->open ("vlt_dump.vcd");
    #endif
    top->din = 0;
    top->dout1 = 0;
 
    NumberTransform<int> NT(16,8);
    ofstream originfile;
    originfile.open("origin.dat");

    while (main_time < 1000 && !Verilated::gotFinish()) {
        x = A*sin(w*main_time + q); 
	y = NT.D2I(x);
	originfile << x << endl;
        top->din = y;
        top->eval();

        #if VM_TRACE
            if (tfp) tfp->dump (main_time);
        #endif
        main_time++;
    }  
    originfile.close();
    top->final();
    #if VM_TRACE
	if (tfp) tfp->close();
    #endif

    exit(0L);
}

